<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>快吃管理系统</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/main.css"/>
    <script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.min.js"></script>
   <script src="__PUBLIC__/js/layer/layer.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/libs/modernizr.min.js"></script>
</head>
<body>
<div class="container clearfix">
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list" style="background:#fff; border:0px"><i class="icon-font"></i>修改食堂信息</div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form  id="myform">
                    <table class="insert-tab" width="100%">
                        <tbody>   
                        {volist name='data' id='v'}                        
                            <tr>
                                <th><i class="require-red">*</i>食堂名称：</th>
                                <td>
                                <input name='restaurant_id' style="display:none" type="text" value="{$v.restaurant_id}" />
                                    <input class="common-text required" id="title" name="restaurant_name" size="85" value="{$v.restaurant_name}" style="width:300px" type="text">
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>食堂负责人：</th>
                                <td>
                                    <input class="common-text required" id="title" name="restaurant_user" size="85" value="{$v.restaurant_user}" style="width:300px" type="text">
                                </td>
                            </tr>              
                            <tr>
                                <th><i class="require-red">*</i>购买价格：</th>
                                <td>
                                    <input class="common-text required" id="title" name="res_user_number" size="85" value="{$v.res_user_number}" type="text" onkeyup="value=value.replace(/[^\d.]/g,'')" style="width:300px">
                                </td>
                            </tr>

                            <tr>
                               <th><i class="require-red">*</i>食堂图片：</th>
                               <td>
                                    <input name='img' type='file' value="{$v.restaurant_img}"><br>
                                    <img src="__PUBLIC__/../uploads/canteen/{$v.restaurant_img}" id="img" height="75px">
                                </td>
                            </tr>
                            </tr> 
                           <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="button">
                                    <input class="btn btn6" onclick="back()" value="返回" type="button">
                                </td>
                            </tr>
                            {/volist}
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
<script type="text/javascript">
    function back()
    {
         window.location.href="{:url('Canteen/canteenmessage')}";
    }
    $('.mr10').click(function(){ 
        var restaurant_name=$('input[name=restaurant_name]');
        var restaurant_user=$('input[name=restaurant_user]');
        var res_user_number=$('input[name=res_user_number]');
        if(restaurant_name.val()=="")
        {
            layer.msg('食堂名称不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            restaurant_name.focus();
            return ;
        }
        if(restaurant_user.val()=="")
        {
            layer.msg('食堂负责人不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            restaurant_user.focus();
            return ;
        }

        if(res_user_number.val()=="")
        {
            layer.msg('负责人电话不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            res_user_number.focus();
            return ;
        }


        var formData = new FormData($("#myform")[0]);//获取表单数据        
          $.ajax({
               url: "{:url('Canteen/updatefun')}",//提交地址
               type: 'POST',
               data: formData,
               async: false,
               cache: false,
               contentType: false,
               processData: false,
               success: function (returndata) {
                if(returndata.code=='1'){
                  if(returndata.data!="")
                    $('#img').attr("src","__PUBLIC__/../uploads/canteen/"+returndata.data);
                  layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                    window.location.href="{:url('Canteen/canteenmessage')}"; 
                  });
                }
                else
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
               },
               error: function (returndata) {
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

           }
          });
    });
</script>
</html>